\chapter{Hopfield e problemas mal colocados}
\label{HOPDEMO}
\section{Exemplo de fun\c{c}\~{a}o para o m\'{e}todo A}

\texttt{function UL = MetA(T,U)}

\texttt{\% Fun\c{c}\~{a}o para solu\c{c}\~{a}o de um sistema de equa\c{c}\~{o}es
diferenciais }

\texttt{\% utilizando-se o M\'{e}todo A descrito em: }

\texttt{\% }

\texttt{\% ''Inversion of Fredholm Integral Equations of the Fist }

\texttt{\% Kind with Fully Connected Neural Networks'' }

\texttt{\% V. Vemur and Gyu-Sang Jangi }

\texttt{\% Journal of the Franklin Institute }

\texttt{\% Vol. 329, No. 2, pp 241-257, 1992 }

\texttt{\%}

\texttt{\% Chamada: UL = MetA(T,U) }

\texttt{\% \qquad \qquad U : Vetor de estados }

\texttt{\% \qquad \qquad T : Tempo }

\texttt{\% \qquad \qquad UL : Pr\'{o}ximo vetor de estados }

\texttt{\%}

\texttt{\% Obs: Coloque as vari\'{a}veis A e b como globais com: }

\texttt{\% \qquad \qquad global A b }

\texttt{\% Marcelo Barros de Almeida - 1998 }

\texttt{global A b }

\texttt{n = length(U); }

\texttt{UL = zeros(n,1); }

\texttt{V = tanh(U);}

\texttt{for i=1:n }

\texttt{\qquad for j=1:n }

\texttt{\qquad \qquad UL(i) = UL(i) - (A(:,i)'*A(:,j))*V(j); }

\texttt{\qquad end }

\texttt{\qquad UL(i) = UL(i) + A(i,i); }

\texttt{end}

\section{Exemplo de fun\c{c}\~{a}o para o m\'{e}todo B}

\texttt{function UL = MetB(T,U)}

\texttt{\% Fun\c{c}\~{a}o para solu\c{c}\~{a}o de um sistema de equa\c{c}\~{o}es
diferenciais }

\texttt{\% utilizando-se o M\'{e}todo B descrito em: }

\texttt{\% }

\texttt{\% ''Inversion of Fredholm Integral Equations of the Fist }

\texttt{\% Kind with Fully Connected Neural Networks'' }

\texttt{\% V. Vemur and Gyu-Sang Jangi }

\texttt{\% Journal of the Franklin Institute }

\texttt{\% Vol. 329, No. 2, pp 241-257, 1992 }

\texttt{\%}

\texttt{\% Chamada: UL = MetB(T,U) }

\texttt{\% \qquad \qquad U : Vetor de estados }

\texttt{\% \qquad \qquad T : Tempo }

\texttt{\% \qquad \qquad UL : Pr\'{o}ximo vetor de estados }

\texttt{\%}

\texttt{\% Obs: Coloque as vari\'{a}veis A e b como globais com: }

\texttt{\% \qquad \qquad global A b }

\texttt{\% Marcelo Barros de Almeida - 1998 }

\texttt{global A b }

\texttt{n = length(U); }

\texttt{UL = zeros(n,1); }

\texttt{V = tanh(U);}

\texttt{for i=1:n }

\texttt{\qquad for j=1:n }

\texttt{\qquad \qquad UL(i) = UL(i) - (A(:,i)'*A(:,j))*V(j); }

\texttt{\qquad end }

\texttt{\qquad UL(i) = UL(i) + A(:,i)'*b; }

\texttt{end}

\section{Fun\c{c}\~{a}o principal}

Estas fun\c{c}\~{o}es podem ser utilizadas no Matlab com o m\'{e}todo de
Runge-Kutta \cite{NUMERICALREC93}, da seguinte forma:
\vspace{1cm}

\texttt{\% Tornando global as matrizes }

\texttt{global A b }

\texttt{\% N\'{u}mero de neur\^{o}nios na rede }

\texttt{n = length(b); }

\texttt{\% Fator m para gera\c{c}\~{a}o da faixa n\'{u}meros aleat\'{o}rios
permitidos }

\texttt{m = 0.001; }

\texttt{\% Fator de escala inicial. Caso a resposta se estabilize em outro valor }

\texttt{\% (ou seja, A*V <> b depois de muitas itera\c{c}\~{o}es), }

\texttt{\% experimente outros fatores de escalas. }

\texttt{k = max(max(A)); }

\texttt{A = A/k; }

\texttt{\% Estimativa inicial }

\texttt{U = (2*rand(n,1)-1)*m; }

\texttt{V = tanh(U);}

\texttt{\% Auxiliares }

\texttt{i = 1; }

\texttt{\% Iteracao }

\texttt{while(sum(abs(A*V-b)) > .001 ) }

\texttt{\qquad [T U] = ode45('MetB',0,50,U,.0001); }

\texttt{\qquad plot(tanh(U)); drawnow; }

\texttt{\qquad U = U(prod(size(U))/n,:)'; }

\texttt{\qquad V = tanh(U); }

\texttt{\qquad i = i + 1}

\texttt{\qquad [A*tanh(V) , b, V] }

\texttt{end }

\texttt{\% Valor final }

\texttt{V = k*V;}

